package com.un10.controller;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.un10.entity.Product;
import com.un10.service.ProductService;
import com.un10.util.Result;

@Controller
public class ProductController {
@Autowired
 ProductService productService;
@RequestMapping("/houtai/getproduct")
@ResponseBody
public Object getprocduct(@RequestParam("page")int page , @RequestParam ("limit")int limit,@RequestParam("proName") String proName,@RequestParam("startPro") String startPro) {
	
			 List<Product> prosclass=productService.findAllProduct((page-1)*limit, limit, proName, startPro);

			
			 if(proName==null || proName=="" ) {
				 proName=null;
				     }
			 if(startPro==null || startPro=="" ) {
				 startPro=null;
				     }
			int count=productService.getCount();
		   System.out.println(proName);
		com.un10.util.Result res=new com.un10.util.Result(0, "",count, prosclass);
	    return  res ;
	}

@RequestMapping("/houtai/deleteProc")
@ResponseBody
public Object deleteProc(@RequestParam("proID") Integer proID) {
	int i = productService.findProductDelete(proID);
	Result res = new Result(0, "", i, true);
	return res;
}
	
@RequestMapping("/houtai/productAdd")
@ResponseBody
public Object productAdd(@RequestParam Map<String, Object> map) {
	

	int i = productService.findProductAdd(map);
	Result res = new Result(0, "", i, true);
	return res;
}

//修改
	@RequestMapping("/houtai/Proedit")
	@ResponseBody
	public Object Proedit(@RequestParam Map<String, Object> map) {
		
		int i = productService.findedit(map);
		Result res = new Result(0, "", i, true);
		return res;
	}
	
	@RequestMapping("/houtai/productUpdate")
	@ResponseBody
	public Object productUpdate(@RequestParam Map<String, Object> map) {
		
		int i = productService.findProductUpdate(map);
		Result res = new Result(0, "", i, true);
		return res;
	}
}
